Raspberry | 您所在的位置:网站首页 › 树莓派Raspberry Pi 配置 › Raspberry |
一、目的
在上一篇《Raspberry-Pi-PICO系列--第四篇 开发环境搭建-Windows系统》我们介绍了windows上开发环境的搭建过程,本篇我们将进一步讲解在windows系统上如何配合Visual Studio Code进行图形化界面开发与调试。 开发调试界面如下: 建议先看一下《Raspberry-Pi-PICO系列--第八篇 高级篇使用SWD接口下载和调试(第一章)_coder.mark的博客-CSDN博客_swd接口》 二、准备 下载Visual Studio Code并安装Visual Studio Code - Code Editing. Redefinedhttps://code.visualstudio.com/ 按照博文《Raspberry-Pi-PICO系列--第五篇 开发环境搭建-Windows系统(基于RT-Studio开发)_coder.mark的博客-CSDN博客》中的下载Zadig驱动并安装https://blog.csdn.net/tianizimark/article/details/123057037。 三、实战1、打开Developer Command Prompt命令行 输入code命令后,Visual Studio Code自动打开,输入Ctrl + Shift + X安装CMake Tool。 安装完毕后点击左下角的齿轮,选择settings 在Settings界面选择Extentions->CMake Tools 找到Cmake: Configure Environment
点击Add Item,输入如下 这一步跟上一篇设置环境变量类似 找到Cmake: Generator,设置成NMake Makefiles,然后关闭Settings。 安装cortex-Debug插件导入工程,打开File->Open Folder,然后定位到pico-examples目录
注意右下角的弹窗,点击Yes,如果没有出现此弹窗,可以在terminal中重新打开Visual Studio Code。 选择GCC 10.3.1 arm-none-eabi,即之前我们安装的工具链。此时Visual Studio Code开始配置,然后从OUTPUT我们可以看到 以上就说明我们环境配置好了,下面我们开始编译 点击Visual Studio Code的最下方的build图标,就会出现编译过程可以点击all图标,然后只编译指定的示例代码,否则会把所有examples都编译一下。 现在我们编译一下hello_usb工程,点击Visual Studio Code最下边的all图标,会弹出一个输入框,在里面输入hello_usb,则编译此工程
默认编译的是Debug版本,可以通过下图的位置进行切换 由于调试需要用的openocd,故需要在windows上先编译openocd1、下载并安装MSYS2 MSYS2https://www.msys2.org
点击完成后,在弹出的命令行窗口中输入命令,更新包数据库和核心包 pacman -Syu安装过程中一直点Y即可,然后窗口会自动关闭 重新打开Msys2命令行窗口 输入 pacman -Su完成整个安装过程。 安装必须的依赖包才能编译openocd,输入下面的命令,然后回车完成安装(安装过程比较久,请耐心等待) pacman -S mingw-w64-x86_64-toolchain git make libtool pkg-config autoconf automake texinfo mingw-w64-x86_64-libusb gcc下面开始下载openocd源码并且编译 需要打开64位版本的Msys2(必须) 进入到raspberry_pi_pico目录(我的是放在桌面下) $ cd /c/Users/你的用户名/Desktop/raspberry_pi_pico $ git clone https://github.com/raspberrypi/openocd.git --branch picoprobe --depth=1 $ cd openocd $ ./bootstrap $ ./configure --enable-picoprobe --disable-werror $ make -j4 configure成功后会有类似如下截图 make命令执行完成后在src目录下有openocd.exe可执行文件 以上我们就准备好openocd工具,在正式调试之前,我们还需要给其中一个pico下载picoprobe固件 picprobe源码编译并下载由于当前picoprobe只支持在linux编译,故此处直接提供编译好的uf2文件 其中picoprobe.uf2文件我们通过USB下载到一块PICO中,这样我们就有了一个swd调试器。 已经编译好的picoprobe固件如下 链接: https://pan.baidu.com/s/1iSthOL8d69iyQyH-qQbmzg 提取码: kfmt 关于SWD调试的内容可以参考Raspberry-Pi-PICO系列--第八篇 高级篇使用SWD接口下载和调试(第一章)_coder.mark的博客-CSDN博客_swd接口https://blog.csdn.net/tianizimark/article/details/123015115 Visual Studio Debug环境配置 1、在pico-examples目录下新建.vscode目录(我们可以在pico-examples目录下右击,然后Git Bash Here) $ mkdir .vscode2、将pico-examples/ide内的文件拷贝至.vscode目录并进行修改 $ cp ide/vscode/launch-raspberrypi-swd.json .vscode/launch.jsonlaunch.json的内容具体如下 { "version": "0.2.0", "configurations": [ { "name": "Pico Debug", "cwd": "${workspaceRoot}", "executable": "${command:cmake.launchTargetPath}", "request": "launch", "type": "cortex-debug", "servertype": "openocd", // This may need to be arm-none-eabi-gdb depending on your system "gdbPath" : "arm-none-eabi-gdb", "device": "RP2040", "searchDir": ["C:/Users/你的用户名/Desktop/raspberry_pi_pico/openocd/tcl"], "configFiles": [ "interface/picoprobe.cfg", "target/rp2040.cfg" ], "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd", "runToMain": true, // Work around for stopping at main on restart "postRestartCommands": [ "break main", "continue" ] } ] }特别注意searchDir需要填写自己的目录 configFiles里面必须改成picoprobe.cfg(因为我们用的picoprobe固件作为调试器固件) gdbPath一定要写成arm-none-eabi-gdb 3、修改Cortex-Debug插件的配置项目 修改openocd path配置为我们编译好的的openocd路径(点击Edit in settings.json) 完整的settings.json文件如下 { "workbench.colorTheme": "Visual Studio Light", "cmake.configureEnvironment": { "PICO_SDK_PATH": "C:\\Users\\你的用户名\\Desktop\\raspberry_pi_pico\\pico-sdk" }, "cmake.generator": "NMake Makefiles", "cmake.configureOnOpen": true, "cortex-debug.openocdPath": "C:/Users/你的用户名/Desktop/raspberry_pi_pico/openocd/src/openocd.exe", "workbench.startupEditor": "none" }其中要注意的是PICO_SDK_PATH必须配置成你的路径 cortex-debug.openocdPath必须配置成你编译出来的openocd.exe 最后需要做的最重要的事情是需要将libusb-1.0.dll这个文件放到C:\Windows\System目录下
该文件可以从下面的链接出下载 libusbhttps://libusb.info/ 至此,所有准备工作都已经准备完毕,开始调试。 1、打开Visual Studio Code 2、我们对blink进行编译调试 3、打开调试窗口,并点击开始按钮 4、如果之前已经完全按照教程操作的话,应该可以看到如下界面 单步调试
至此,我们就完成了完整的开发环境搭建-Windows系统 + Visual Studio Code开发。 |
CopyRight 2018-2019 实验室设备网 版权所有 |